/*
 * @Description: 
 * @Autor: 赵子惠
 * @Date: 2021-09-09 15:30:11
 * @LastEditors: 商晓彬
 * @LastEditTime: 2022-01-04 14:34:18
 */
import { LazyLoadEvent } from "primeng/api";
import { Component, Injector, ViewChild } from "@angular/core";
import { AppComponentBase } from "@shared/common/app-component-base";
import { Table } from "primeng/components/table/table";
import { Paginator } from "primeng/components/paginator/paginator";
import { MessageService } from "@abp/message/message.service";
import { ArrowPresetSearchServiceProxy, StoreFunctionsServiceProxy, CollectBomServiceProxy, BomAnalyseContentDto, CommonServiceProxy } from "@shared/service-proxies/service-proxies";
import { finalize } from "rxjs/operators";
import { FileDownloadService } from '@shared/utils/file-download.service';


@Component({
    selector: 'app-complete-set',
    templateUrl: './complete-set.component.html',
    styleUrls: ['./complete-set.component.less']
})
export class CompleteSetComponent extends AppComponentBase {

    @ViewChild("paginator") paginator: Paginator;
    @ViewChild("dataTable") dataTable: Table;
    bomAnalyseContentDto: BomAnalyseContentDto[];
    model = undefined;
    modelOption = [];
    lotNo = undefined;
    LotNoList = [];
    materialPropertyName = undefined;
    preSuiteStatus = undefined;
    bomStutsOptions = [
        {
            label: "请选择",
            value: undefined,
        },
    ];
    rowdata: any; //子组件传参
    saveFlag = true;
    cpreSuiteStatusOptions = [
        {
            label: '未同步',
            value: '未同步'
        },{
            label: '缺料',
            value: '缺料'
        },{
            label: '未预配套',
            value: '未预配套'
        },{
            label: '预配套中',
            value: '预配套中'
        },{
            label: '已预配套',
            value: '已预配套'
        }
    ]
    constructor(
        injector: Injector,
        private _messageService: MessageService,
        private _arrowPresetSearchServiceProxy: ArrowPresetSearchServiceProxy,
        private _storeFunctionsServiceProxy: StoreFunctionsServiceProxy,
        private _collectBomServiceProxy: CollectBomServiceProxy,
        private _fileDownloadService: FileDownloadService,
        //2021-10-06 曲冰修改
        private _commonServiceProxy: CommonServiceProxy,
    ) {
        super(injector);
    }
    ngOnInit() {
        this.getModelList();
        //2021-10-06 曲冰添加
        this.getLotNoList();
    }
    getTableList(event?: LazyLoadEvent) {
        if (this.primengTableHelper.shouldResetPaging(event)) {
            this.paginator.changePage(0);
            return;
        }
        this._arrowPresetSearchServiceProxy.getBomAalyseCollect(
            //2021-10-06 曲冰修改
            undefined,
            this.model,
            undefined,
            this.lotNo,
            undefined,
            undefined,
            undefined,
            this.materialPropertyName,
            this.preSuiteStatus,
            undefined,
            this.primengTableHelper.getSorting(this.dataTable),
            this.primengTableHelper.getMaxResultCount(this.paginator, event),
            this.primengTableHelper.getSkipCount(this.paginator, event)
        ).pipe(finalize(() => this.primengTableHelper.hideLoadingIndicator())).subscribe(result => {
            this.primengTableHelper.totalRecordsCount = result.totalCount;
            this.primengTableHelper.records = result.items;
            // this.primengTableHelper.records = [{}];
            this.primengTableHelper.hideLoadingIndicator();
        });
    }
    //2021-10-06 曲冰修改
    //获取左侧型号
    getModelList() {
        this._commonServiceProxy.getModelList()
            .pipe(finalize(() => { })).subscribe(result => {
                this.modelOption = result;
            })
    }
    //2021-10-06 曲冰修改
    //根据型号获取对应的发次
    getLotNoList() {
        this._commonServiceProxy.getLotNoList(
            this.model
        )
            .pipe(finalize(() => { })).subscribe(result => {
                this.LotNoList = result
            })
    }
    outExcel() {
        // if (this.saveFlag) {
        //     this.saveFlag = false;
        this._arrowPresetSearchServiceProxy.getMaterialsContentToExcel(
            undefined,
            this.model,
            undefined,
            this.lotNo,
            undefined,
            undefined,
            undefined,
            this.materialPropertyName,
            this.preSuiteStatus,
            undefined,
            undefined,
            undefined,
            undefined
        )
            .subscribe(result => {
                // this.saveFlag = true;
                // this._fileDownloadService.downloadTempFile(result);
                window.open(result);
                URL.revokeObjectURL(result);
            });
        // }
    }
    reset() {
        this.model = undefined;
        this.lotNo = undefined;
        this.materialPropertyName = undefined;
        this.preSuiteStatus = undefined;
        this.LotNoList = [];
    }
}
